<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>ATSread</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="ATSinterpread.html" title="ATSinterpread" />
    <link rel="next" href="ATSreadnz.html" title="ATSreadnz" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">ATSread</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="ATSinterpread.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="ATSreadnz.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="ATSread"></a>
      <div class="titlepage"></div>
      <a id="IndexATSread" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">ATSread</span>
        </h2>
        <p>ATSread —  reads data from an ATS file.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90853584"></a>
        <h2>Description</h2>
        <p>
            <span class="emphasis"><em>ATSread</em></span> returns the amplitude (<span class="emphasis"><em>kamp</em></span>) and frequency (<span class="emphasis"><em>kfreq</em></span>) information of a user specified partial contained in the ATS analysis file at the time indicated by the time pointer <span class="emphasis"><em>ktimepnt</em></span>.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90896672"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">kfreq, kamp <span class="command"><strong>ATSread</strong></span> ktimepnt, iatsfile, ipartial</pre>
      </div>
      <div class="refsect1">
        <a id="idp90898896"></a>
        <h2>Initialization</h2>
        <p>
            <span class="emphasis"><em>iatsfile</em></span> – the ATS number (n in ats.n) or the name in quotes of the analysis file made using <a class="ulink" href="http://www-ccrma.stanford.edu/~juan/ATS.html" target="_top"><em class="citetitle">ATS</em></a>.
        </p>
        <p>
            <span class="emphasis"><em>ipartial</em></span> – the number of the analysis partial to return the frequency in Hz and amplitude.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90902544"></a>
        <h2>Performance</h2>
        <p>
            <span class="emphasis"><em>kfreq, kamp</em></span> - outputs of the <span class="emphasis"><em>ATSread</em></span> unit. These values represent the frequency and amplitude of a specific partial selected by the user using <span class="emphasis"><em>ipartial</em></span>. The partials' informations are derived from an ATS analysis. <span class="emphasis"><em>ATSread</em></span> linearly interpolates the frequency and amplitude between frames in the ATS analysis file at k-rate. The output is dependent on the data in the analysis file and the pointer <span class="emphasis"><em>ktimepnt</em></span>.
        </p>
        <p><span class="emphasis"><em>ktimepnt</em></span> – The time pointer in seconds used to index the ATS file. Used for <span class="emphasis"><em>ATSread</em></span> exactly the same as for <a class="link" href="pvoc.html" title="pvoc"><em class="citetitle">pvoc</em></a> and <a class="link" href="ATSadd.html" title="ATSadd"><em class="citetitle">ATSadd</em></a>.</p>
      </div>
      <div class="refsect1">
        <a id="idp90909376"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the ATSread opcode. It uses the file <a class="ulink" href="examples/ATSread.csd" target="_top"><em class="citetitle">ATSread.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp90911232"></a>
          <p class="title">
            <strong>Example 68. Example of the ATSread opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;RT audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o ATSread.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="oblock">instr</span> 1	<span class="comment">; "beats.ats" is created by atsa</span>

ktime	<span class="opc">line</span>    0, p3, 2
kfreq, kamp	<span class="opc">ATSread</span>  ktime, "beats.ats", 100
aout	<span class="opc">oscili</span>  0.8, kfreq, 1
	<span class="opc">outs</span>	aout, aout
 
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="comment">;sine wave.</span>
<span class="stamnt">f</span> 1 0 16384 10 1

<span class="stamnt">i</span> 1 0 2 
<span class="stamnt">e</span>

<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
        <p>Here we're using <span class="emphasis"><em>ATSread</em></span> to get the 100th partial's frequency and amplitude data out of the 'beats.ats' ATS analysis file. We're using that data to drive an oscillator, but we could use it for anything else that can take a k-rate input, like the bandwidth and resonance of a filter etc.
      </p>
        <p>
      Here is another example of the ATSread opcode. It uses the file <a class="ulink" href="examples/ATSread-2.csd" target="_top"><em class="citetitle">ATSread-2.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp90915264"></a>
          <p class="title">
            <strong>Example 69. Example 2 of the ATSread opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-odac -d -m128
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">;example by joachim heintz</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

giSine    <span class="ohdr">ftgen</span>     0, 0, 1024, 10, 1
gSfile    <span class="op">=</span>         "fox.ats"
giNumParts <span class="opc">ATSinfo</span>  gSfile, 3 <span class="comment">;overall number of partials</span>
giDur     <span class="opc">ATSinfo</span>   gSfile, 7 <span class="comment">;duration </span>
          <span class="ohdr">seed</span>      0


  <span class="oblock">instr</span> ReadOnePartial
iPartial  <span class="op">=</span>         p4
p3        <span class="op">=</span>         giDur
ktime     <span class="opc">line</span>      0, giDur, giDur
          <span class="opc">prints</span>    "Resynthesizing partial number <span class="op">%</span>d.\n", iPartial
kFq,kAmp  <span class="opc">ATSread</span>   ktime, gSfile, iPartial
kAmp      <span class="opc">port</span>      kAmp, .1 <span class="comment">;smooth amplitudes - still not satisfactoring</span>
aOut      <span class="opc">poscil</span>    kAmp, kFq, giSine
aOut      <span class="opc">linen</span>     aOut, 0, p3, .01 <span class="comment">;anti-click</span>
          <span class="opc">outs</span>      aOut<span class="op">*</span>10, aOut<span class="op">*</span>10

<span class="comment">;start next instr: normal speed, three loops, pause between loops one second</span>
          <span class="opc">event_i</span>   "i", "MasterRand", giDur<span class="op">+</span>3, 1, 1, 3, 2
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> MasterRand
  <span class="comment">;random selections of 10 partials per second, overlapping</span>
iSpeed    <span class="op">=</span>         p4 <span class="comment">;speed of reading / playing</span>
iNumLoops <span class="op">=</span>         p5 <span class="comment">;number of loops</span>
iPause    <span class="op">=</span>         p6 <span class="comment">;length of pause between loops</span>
          <span class="opc">prints</span>    "Resynthesizing <span class="opc">random</span> partials.\n"
p3        <span class="op">=</span>         (giDur<span class="op">/</span>iSpeed<span class="op">+</span>iPause) <span class="op">*</span> iNumLoops
<span class="comment">;start next instr: half speed, three loops, three seonds pause between loops</span>
          <span class="opc">event_i</span>   "i", "MasterArp", p3<span class="op">+</span>3, 1, .5, 3, 3
<span class="comment">;loop over duration plus pause</span>
<span class="olabel">loop</span><span class="op">:</span>
          <span class="octrl">timout</span>    0, giDur<span class="op">/</span>iSpeed<span class="op">+</span>iPause, <span class="olabel">play</span>
          <span class="opc">reinit</span>    <span class="olabel">loop</span>
<span class="olabel">play</span><span class="op">:</span>
gkTime    <span class="opc">line</span>      0, giDur<span class="op">/</span>iSpeed, giDur <span class="comment">;start time from 0 in each loop</span>
kTrig     <span class="opc">metro</span>     10 <span class="comment">;10 new partials per second</span>
 <span class="comment">;call subinstrument if trigger and no pause</span>
 <span class="octrl">if</span> kTrig <span class="op">==</span> 1 <span class="op">&amp;&amp;</span> gkTime <span class="op">&lt;</span> giDur then
kPart     <span class="opc">random</span>    1, giNumParts<span class="op">+</span>.999
          <span class="opc">event</span>     "i", "PlayRand", 0, 1, <span class="opc">int</span>(kPart)
 <span class="octrl">endif</span>

  <span class="oblock">endin</span>
  
  <span class="oblock">instr</span> MasterArp
  <span class="comment">;argeggio-like reading and playing of partials </span>
iSpeed    <span class="op">=</span>         p4 <span class="comment">;speed of reading / playing</span>
iNumLoops <span class="op">=</span>         p5 <span class="comment">;number of loops</span>
iPause    <span class="op">=</span>         p6 <span class="comment">;length of pause between loops</span>
          <span class="opc">prints</span>    "Arpeggiating partials.\n"
p3        <span class="op">=</span>         (giDur<span class="op">/</span>iSpeed<span class="op">+</span>iPause) <span class="op">*</span> iNumLoops
<span class="olabel">loop</span><span class="op">:</span>
          <span class="octrl">timout</span>    0, giDur<span class="op">/</span>iSpeed<span class="op">+</span>iPause, <span class="olabel">play</span>
          <span class="opc">reinit</span>    <span class="olabel">loop</span>
<span class="olabel">play</span><span class="op">:</span>
gkTime    <span class="opc">line</span>      0, giDur<span class="op">/</span>iSpeed, giDur
kArp      <span class="opc">linseg</span>    1, (giDur<span class="op">/</span>iSpeed)<span class="op">/</span>2, giNumParts, (giDur<span class="op">/</span>iSpeed)<span class="op">/</span>2, 1 <span class="comment">;arp up and down</span>
kTrig     <span class="opc">metro</span>     10 <span class="comment">;10 new partials per second</span>
 <span class="octrl">if</span> kTrig <span class="op">==</span> 1 <span class="op">&amp;&amp;</span> gkTime <span class="op">&lt;</span> giDur then
          <span class="opc">event</span>     "i", "PlayArp", 0, 5, <span class="opc">int</span>(kArp)
 <span class="octrl">endif</span>

<span class="comment">;exit csound when finished</span>
          <span class="opc">event_i</span>   "i", "End", p3<span class="op">+</span>5, 1
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> PlayRand
iPartial  <span class="op">=</span>         p4
kFq,kAmp  <span class="opc">ATSread</span>   gkTime, gSfile, iPartial
kamp      <span class="opc">port</span>      kAmp, .15 <span class="comment">;smooth amplitudes</span>
aOut      <span class="opc">poscil</span>    kAmp, kFq, giSine
aOut      <span class="opc">linen</span>     aOut, .01, p3, .01
          <span class="opc">outs</span>      aOut, aOut
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> PlayArp
kCount    <span class="opc">init</span>      1 <span class="comment">;k-cycle</span>
iPartial  <span class="op">=</span>         p4
kFq,kAmp  <span class="opc">ATSread</span>   gkTime, gSfile, iPartial
 <span class="octrl">if</span> kCount <span class="op">==</span> 1 then <span class="comment">;get freq from first k-cycle</span>
kModFq    <span class="op">=</span>         kFq
  <span class="comment">;avoid to go with 0 Hz as this blocks the mode filter</span>
  <span class="octrl">if</span> kModFq <span class="op">==</span> 0 then
          <span class="opc">turnoff</span>
  <span class="octrl">endif</span>
 <span class="octrl">endif</span>
iVol      <span class="opc">random</span>    <span class="op">-</span>42, <span class="op">-</span>12 <span class="comment">;db</span>
iOffset   <span class="opc">random</span>    .01, .1 <span class="comment">;no too regularily ...</span>
aImp      <span class="opc">mpulse</span>    <span class="opc">ampdb</span>(iVol), p3, iOffset
iQ        <span class="opc">random</span>    500, 5000
aOut      <span class="opc">mode</span>      aImp, kModFq, iQ
aOut      <span class="opc">linen</span>     aOut, 0, p3, p3<span class="op">/</span>3
          <span class="opc">outs</span>      aOut, aOut
kCount    <span class="op">=</span>         2
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> End
          <span class="opc">exitnow</span>
  <span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> "ReadOnePart<span class="stamnt">i</span>al" 0 1 10
<span class="stamnt">e</span> 999
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp90917184"></a>
        <h2>See also</h2>
        <p><a class="link" href="ATSreadnz.html" title="ATSreadnz"><em class="citetitle">ATSreadnz</em></a>, 
            <a class="link" href="ATSinfo.html" title="ATSinfo"><em class="citetitle">ATSinfo</em></a>, 
            <a class="link" href="ATSbufread.html" title="ATSbufread"><em class="citetitle">ATSbufread</em></a>, 
            <a class="link" href="ATScross.html" title="ATScross"><em class="citetitle">ATScross</em></a>, 
            <a class="link" href="ATSinterpread.html" title="ATSinterpread"><em class="citetitle">ATSinterpread</em></a>, 
            <a class="link" href="ATSpartialtap.html" title="ATSpartialtap"><em class="citetitle">ATSpartialtap</em></a>, 
            <a class="link" href="ATSadd.html" title="ATSadd"><em class="citetitle">ATSadd</em></a>, 
            <a class="link" href="ATSaddnz.html" title="ATSaddnz"><em class="citetitle">ATSaddnz</em></a>, 
            <a class="link" href="ATSsinnoi.html" title="ATSsinnoi"><em class="citetitle">ATSsinnoi</em></a></p>
      </div>
      <div class="refsect1">
        <a id="idp90926656"></a>
        <h2>Credits</h2>
        <p>
            </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Alex Norman</td>
          </tr>
          <tr>
            <td>Seattle,Washington</td>
          </tr>
          <tr>
            <td>2004</td>
          </tr>
        </table>
        <p>
        </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="ATSinterpread.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="ATSreadnz.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">ATSinterpread </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> ATSreadnz</td>
        </tr>
      </table>
    </div>
  </body>
</html>
